package com.tougutips.cookbook.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.tougutips.cookbook.dto.NewCookbookDto;
import com.tougutips.cookbook.entity.Cookbook;
import com.tougutips.cookbook.service.CookbookService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static sun.rmi.runtime.Log.getLog;

/**
 * @author MJ
 * description:
 * Date: 2022/7/21 -12:02
 * @Todo:
 */

@RestController
@RequestMapping("/content/cookbook")
public class CookbookController extends BaseController {

    @Autowired
    private CookbookService cookbookService;

    @GetMapping
    public TableDataInfo getListByPage(){
        logger.info("查询菜谱信息");
        startPage();
        List<Cookbook> list = cookbookService.list();
        return getDataTable(list);
    }

    @PostMapping
    public R addCookbook(@RequestBody NewCookbookDto newCookbookDto){
        logger.info("新增菜谱");
        R r = cookbookService.addCookbook(newCookbookDto);
        return r;
    }
}
